var Res = {
	opt: null,
	actionSheetO:null,
	actionSheetT:null,
	actionSheetE:null,
	actionSheetR:null,
	defaultIMG: "student/students.png",
	count: 8, //每次下拉刷新个数
	gnTitle: function(opt) {
		Res.opt = opt;
		var html = '';
		if (opt.leftFn)
			Res.leftFn = opt.leftFn;
		else
			Res.leftFn = WinClose;
		Res.rightFn = opt.rightFn;
		Res.switchFn = opt.switchFn;
		Res.bottomFn = opt.bottomFn;
		// var content = "";
		if (opt.isSwitch) {
			html += '<div id="header" class="ub ub-ver ub-img1 ufp9">';
			if (opt.leftFn){
				html += '    <div id="leftBtn" class="uw4 ub ub-ac" ontouchstart="zy_touch()" onclick="Res.leftClick();">'+
					    '        <div class="uw1 uh2 ub-img im_back1 uml_1"></div>'+
					    '    </div>';
			}		    
			html += '<div class="ub-f1 ub_center ub">';
			for (var i=0; i<opt.items.length; ++i) {
				var selected = "";
				var upp65 = "";
				if (opt.items[i].url == "notice")
					upp65 = "upp65";

				if (GetLS("selectedNum")){
					if (i == GetLS("selectedNum"))
						selected = "selected";
				} else if (i == 0)
					selected = "selected";
				var icon_bottom = (opt.items[i].url == "project"||opt.items[i].url == "course"||opt.items[i].url == "myExam"||opt.items[i].url == "myErrSet")?'<div class="ub-img im_bottom uh1 uw1 uml_p3 visib"></div>':'';
				html += '<div id="'+ opt.items[i].url +'" class="' + upp65 + ' ub ub-ac ub-pc up_title_item ub-f1 tx-c ' + selected + '" ontouchstart="zy_touch()" onclick="Res.switch(\''+ opt.items[i].num +'\',' + opt.items.length + ',' + opt.items[i].itemNum + ')">'+ opt.items[i].title + icon_bottom + '</div>';
			}
			html += '</div>';
			if (opt.items.length)
				html += '<div id="selectBorder" class="uhp1 bc_green" style="width:' + 100/opt.items.length + '%;margin-left:' + 100*GetLS("selectedNum")/opt.items.length + ';"></div>';
			if (opt.rightFn){
				html +=	'    <div id="rightBtn" class="uw4 ub_center ufp9" ontouchstart="zy_touch()" onclick="Res.rightClick();">';

				if (opt.rightTitle)
					html += '	<div class="ub ub-ac ub-pc uh1p5 hide c_wht" style="padding:0.3em; border-radius:0.2em;">'+ opt.rightTitle +'</div>';
				else
					html += '	<div class="uw2 ub ub-ac ub-pc uh1p5 ub_img im_'+ opt.rightImg +' hide"></div>';
			}	

			html += '    </div>'+
				    '</div>';
		} else {
		    html += '<div id="header" class="ub c_wht bc_black">'+
				    '    <div id="leftBtn" class="uw4 ub ub-ac" ontouchstart="zy_touch()" onclick="Res.leftClick();">'+
				    '        <div class="uw1 uh2 ub-img1 im_back1 uml_1"></div>'+
				    '    </div>'+
				    '    <div id="title" class="up_title ub-f1 ut-s tx-c">'+ opt.title +'</div>'+
				    '    <div id="rightBtn" class="uw4 ub_center ufp9" ontouchstart="zy_touch()" onclick="Res.rightClick();">';
					if (opt.rightTitle)
						html += '	<div class="ub ub-ac ub-pc uh1p5 c_wht" style="padding:0.3em; border-radius:0.2em;">'+ opt.rightTitle +'</div>';
					else
						html += '	<div class="uw2 ub ub-ac ub-pc uh1p5 ub_img im_'+ opt.rightImg +'"></div>';
			html += '    </div>'+
				    '</div>';
		}
		if ($("#header").length)
			$("#header").remove();
		$("body").prepend(html);
		if (opt.isSwitch) {
		 //    var topMargin = $("#header").outerHeight();
		 //    uexWindow.openMultiPopover(content,"multiWindow", 0, 0, topMargin, $("#content").width(), $("#content").height(), '', 0, 0);
		 //    uexWindow.setSelectedPopOverInMultiWindow('multiWindow', 0);
			// uexWindow.cbOpenMultiPopover = opt.cb;
		}
	},
	leftClick: function() {
		Res.leftFn();
	},
	rightClick: function() {
		if (Res.rightFn)
			Res.rightFn();
	},
	switch: function(i,length,itemNum) {
		Res.borderSwitch(itemNum,length);
		var t = 100/length*itemNum + "%";
		SetLS("swipenum", itemNum);
		CCall('$(".linebox").css({"-webkit-transform":"translate(-'+t+')","-webkit-transition":"300ms linear"} )');
		var type = i;
		var $this = $(event.currentTarget);
		var certypeFn = function(){ 
			$ajax({
				url: "/direction/list",
				success: function(res) {
					var ctypename = [];
					var res = res.result.results;
					ctypename.push("查看全部");
					for (var i = 0; i < res.length; i ++)
						ctypename.push(res[i].name);
					if (type == "0"){
						ActionSheet("项目IT方向", "取消", ctypename, function(data){
							var ctypeId = res[data-1]?res[data-1]._id:"";
							Project.projectIndexInit(ctypeId);
						});
					}
					if (type == "1"){
						ActionSheet("课程IT方向", "取消", ctypename, function(data){
							var ctypeId = res[data-1]?res[data-1]._id:"";
							Course.courseIndexInit(ctypeId);
						});
					}
				}
			});
		}	
		$(".im_bottom").addClass("visib");	
		if (i=="0"&&GetLS("tab").url=="tab0"){
			$this.children(".im_bottom").removeClass("visib");
			Res.actionSheetT = null;
			if (!Res.actionSheetO){
				Res.actionSheetO = true;
				return;
			}	
			certypeFn();
		} else if (i=="1"&&GetLS("tab").url=="tab0"){ 
			$this.children(".im_bottom").removeClass("visib");
			Res.actionSheetO = null;
			if (!Res.actionSheetT){
				Res.actionSheetT = true;
				return;
			}	
			certypeFn();
		} else { 
			Res.actionSheetO = null;
			Res.actionSheetT = null;
		}	
		var examtypeFn = function(){ 
			$ajax({
				url:"/user/getCourseProject",
				data:{
					field: "course"
				},
				success: function(res) {
					var ctypename = [];
					var res = res.result;
					ctypename.push("查看全部");
					for (var i = 0; i < res.length; i ++)
						ctypename.push(res[i].name);
					if (type == "0"){
						ActionSheet("选择课程", "取消", ctypename, function(data){
							var ctypeId = res[data-1]?res[data-1]._id:"";
							Exam.exaInit(ctypeId);
						});
					}
					if (type == "1"){
						ActionSheet("选择课程", "取消", ctypename, function(data){
							var ctypeId = res[data-1]?res[data-1]._id:"";
							Exam.errInit(ctypeId);
						});
					}
				}
			});
		}
		if (i=="0"&&GetLS("tab").url=="tab2"){
			$this.children(".im_bottom").removeClass("visib");
			Res.actionSheetR = null;
			if (!Res.actionSheetE){
				Res.actionSheetE = true;
				return;
			}	
			examtypeFn();
		} else if (i=="1"&&GetLS("tab").url=="tab2"){ 
			$this.children(".im_bottom").removeClass("visib");
			Res.actionSheetE = null;
			if (!Res.actionSheetR){
				Res.actionSheetR = true;
				return;
			}	
			examtypeFn();
		} else { 
			Res.actionSheetE = null;
			Res.actionSheetR = null;
		}
        //SendNotification("poverIndex", {poverIndex:i});
    },
    borderSwitch: function(itemNum,length){ 
    	$("#selectBorder").css("margin-left",100*itemNum/length + "%");
        $(".up_title_item").removeClass("selected");
        $("#header .up_title_item").eq(itemNum).addClass("selected");
    },
    gnCertificate: function(photo,name,organization){ 
    	certificate = 	'<div class="ub ub-f1 ubb b_gra up1">' + 
						'	<div class="ub-img1 uw45 uh8" style="background-image:url(' + photo + ')"></div>' + 
						'	<div class="ub ub-f1 ub-ver">' + 
						'		<div class="upp5 ut-s">' + name + '</div>' + 
						'		<div class="ub ufp7 upp5 ub-ac ub-pc">' + 
						'			<div class="ub-img1 uw1 uh1 im_teacher"></div>' + 
						'			<div class="ub-f1 ut-s">　颁证机构 : ' + organization + '</div>' + 
						'		</div>' + 
						'	</div>' + 
						'</div>';
		return 	certificate;			
    },
	gnCourse: function(photo,name,teachername,classhour,des,id,callback){ 
		var course ='<div data-id="' + id + '" class="ub ub-f1 ubb b_gra up1" ontouchstart="zy_touch()" onclick="' + callback + '">' + 
					'	<div class="ub-img1 uw45 uh8" style="background-image:url(' + photo + ')"></div>' + 
					'	<div class="ub ub-f1 ub-ver">' + 
					'		<div class="upp5 ut-s">' + name + '</div>' + 
					'		<div class="ub ufp7">' + 
					'			<div class="ub-f1 ub upp5 ub-ac ub-pc">' + 
					'				<div class="ub-img1 uw1 uh1 im_teacher"></div>' + 
					'				<div class="ub-f1">　讲师 : ' + teachername + '</div>' + 
					'			</div>' + 
					'			<div class="ub-f1 ub upp5 ub-ac ub-pc">' + 
					'				<div class="ub-img1 uw1 uh1 im_teacher"></div>' + 
					'				<div class="ub-f1">　课时 : ' + classhour + '课时</div>' + 
					'			</div>' + 
					'		</div>' + 
					'		<div class="ufp7 upp5 t-gra">' + des + '</div>' + 
					'	</div>' + 
					'</div>';
		return course;			
	}
}

var Menu = {
	40:{
		title:"学生",
		items: [
			["tab0", "首页"],
			["tab1", "学习"],
			["tab2", "记录"],
			["tab3", "设　置"]
		]
	},
	201:{
		title:"辅导老师",
		items: [
			["tab0", "首页"],
			["tab1", "学习"],
			["tab2", "记录"],
			["tab3", "设置"]
		]
	}
}
var Swipe = { 
	index:{
		title: "index",
		items:[
			["index_freecourse","公开课"],
			["index_course","课　程"],
			["index_certificate","证　书"]
		]
	},
	study:{
		title: "study",
		items:[
			["study_myCourse","课　程"],
			["study_myCertificate","证　书"]
		]
	},
	exam:{
		title: "exam",
		items:[
			["exam_exam","考试记录"],
			["exam_errorset","我的错题"]
		]
	},
	set:{
		title: "set",
		items:[
			["set","设置"],
			["aboutme","关于我们"]
		]
	}	
}	
var Swipe2 = { 
	items:[
		["index_freecourse","公开课",0,3],
		["index_course","课　程",1,3],
		["index_certificate","证　书",2,3],
		["study_myCourse","课　程",0,2],
		["study_myCertificate","证　书",1,2],
		["exam_exam","考试记录",0,2],
		["exam_errorset","我的错题",1,2],
		["set","设置",0,1]
	]
}	
var Role = { //用户类型
    ADMIN: 0, //平台管理员
    PROADMIN: 10, //课程管理员
    PROVIDER: 20, //课程提供商
    TUTOR: 30, //辅导老师
    STUDENT: 40, //学生
    VISITOR: 1000 //游客
};
var STULEVEL = { //学生级别
    LAYMAN: 1, //门外汉
    TRAINEE: 2, //实习生
    ENGINEER: 3, //工程师
    PROJECTMANAGER: 4 //项目经理
};
var STULEVELTEXT = { //学生级别
    1: "门外汉", //门外汉
    2: "实习生", //实习生
    3: "工程师", //工程师
    4: "项目经理" //项目经理
};
var STATUS = { //各种状态
        COMMIT: 1, //提交
        UNCOMMIT: 2, //未提交
        PASS: 3, //通过
        REJECT: 4, //拒绝
        UNPUBLISH: 0, //未发布
        SHELVES: 5, //上架
        UNDERCARRIAGE: 6, //下架
        UNREAD: 7, //未读
        READ: 8, //已读
        VERIFYING: 9, //审核中

        NORMAL: 10, //账号正常
        ACTIVE: 11, //屏蔽
        UNACTIVE: 12, //封号
};
var CHAPTERTYPE = {
    CHAPTER: 0, // 正常章节
    COURSEEXAM: 1, //课程结业考试
};
var EXAMTYPE = { //试题类型
    SINGLE_CHOICE: 1, //单选，
    MULTIPLE_CHOICE: 2, //多选，
    JUDGE: 3, //判断，
    LIGATURE: 4, //连线（匹配）,
    SORT: 5, //排序
};
var EXAMTYPE_LABEL = { //试题类型
    1: "单选题", //单选，
    2: "多选题", //多选，
    3: "判断题", //判断，
    4: "连线题", //连线（匹配）,
    5: "排序题" //排序,
};
var PROJECTTYPE = {
    BLOCK: 0, // 功能块
    POINT: 1, // 功能点
    CHAPTER: 2 //章节
};